# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>

pkgbase=modemmanager
pkgname=(
  modemmanager
  libmm-glib
)
pkgver=1.22.0
pkgrel=1
pkgdesc="Mobile broadband modem management service"
url="https://www.freedesktop.org/wiki/Software/ModemManager/"
arch=(loong64 x86_64)
license=(
  GPL2
  LGPL2.1
)
depends=(
  libgudev
  libmbim
  libqmi
  mobile-broadband-provider-info
  polkit
  ppp
  systemd
)
makedepends=(
  bash-completion
  git
  gobject-introspection
  gtk-doc
  meson
  vala
)
checkdepends=(
  python-dbus
  python-gobject
)
_commit=03f786ce66360d67c669f4f122f8aa458e6f01ea  # tags/1.22.0^0
source=("git+https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd ModemManager
  git describe --tags | sed 's/-rc/rc/;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd ModemManager
}

build() {
  local meson_options=(
    -D dbus_policy_dir=/usr/share/dbus-1/system.d
    -D dist_version="\"$pkgver-$pkgrel\""
    -D gtk_doc=true
    -D polkit=permissive
    -D vapi=true
  )

  arch-meson ModemManager build "${meson_options[@]}"
  meson compile -C build
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_modemmanager() {
  depends+=(
    libgudev-1.0.so
    libg{lib,object,io,module}-2.0.so
    libmbim-glib.so
    libmm-glib.so
    libqmi-glib.so
    libsystemd.so
  )
  optdepends=(
    'usb_modeswitch: install if your modem shows up as a storage drive'
  )

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"
  _pick libmm usr/include
  _pick libmm usr/lib/girepository-1.0
  _pick libmm usr/lib/libmm-glib.so*
  _pick libmm usr/lib/pkgconfig
  _pick libmm usr/share/gir-1.0
  _pick libmm usr/share/gtk-doc/html/libmm-glib
  _pick libmm usr/share/vala
}

package_libmm-glib() {
  pkgdesc="ModemManager library"
  depends=(libg{lib,object,io}-2.0.so)
  provides=(libmm-glib.so)

  mv libmm/* "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
